/* main.c */

#include <avr/io.h>
#include "eeprom.h"
#include "usart.h"
#include "delay.h"

#define UBRR (16000000 / 16 / 19200 - 1)

void message(char* s)
{
   usart_tx(12);
   delay_ms(5);
   usart_tx_string(s);
   delay_ms(250);
   delay_ms(250);
   delay_ms(250);
   delay_ms(250);
}

int main(void)
{
   usart_init(UBRR);
   
   while (1)
   {
      usart_tx_string("\r\n");
      usart_tx_string("    _            _       _\r\n");
      usart_tx_string("   / \\   _ __ __| |_   _(_)_ __   ___\r\n");
      usart_tx_string("  / _ \\ | '__/ _` | | | | | '_ \\ / _ \\\r\n");
      usart_tx_string(" / ___ \\| | | (_| | |_| | | | | | (_) |\r\n");
      usart_tx_string("/_/   \\_\\_|  \\__,_|\\__,_|_|_| |_|\\___/\r\n");
      usart_tx_string("\r\n");
      
      usart_tx_string("(F)ill EEPROM (E)rase EEPROM (D)ump EEPROM\r\n");
      
      unsigned c = usart_rx();
      
      switch (c)
      {
         case 'F':
            usart_tx_string("Filling EEPROM\r\n");
            for (int i = 0; i < 512; i++) {
               eeprom_write(i, i % 255);
            }
            break;
         case 'E':
            usart_tx_string("Erasing EEPROM\r\n");
            for (int i = 0; i < 512; i++) {
               eeprom_write(i, 0xff);
            }
            break;
         case 'D':
            usart_tx_eeprom_hexdump();            
            break;
         default:
            usart_tx_string("Huh?\r\n");
      }
   }
   
   return 0;
}
